package com.whsxt.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

/**
 * @Author 武汉尚学堂
 * 该Servlet只负责页面跳转
 */
@WebServlet("/page.do")
public class PageServlet  extends HttpServlet {


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String service = req.getParameter("service");
        try {
            //通过反射调用方法
            Method m = this.getClass().getDeclaredMethod(service, HttpServletRequest.class, HttpServletResponse.class);
            m.invoke(this,req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 跳转到WEB-INF/view/main.jsp
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void main(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/main.jsp").forward(req,resp);
    }

    /**
     * 去员工列表页面
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void userList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/user/list.jsp").forward(req,resp);
    }

    /**
     * 去修改密码页面
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void updatePwd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/user/updatePwd.jsp").forward(req,resp);
    }

    /**
     * 去修改图像页面
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void updateImg(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/user/updateImg.jsp").forward(req,resp);
    }


    /**
     * 去客户列表页面
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void customerList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //查询业务员数据
        //将业务员数据放入到作用域中
        req.getRequestDispatcher("WEB-INF/view/customer/list.jsp").forward(req,resp);
    }
}
